<template>
<el-dialog
    :title="$t('appsetting.member_level')"
    v-model="dialogVisible"
    @close="dialogFormVisible"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
  >
    <!--form表单-->
    <el-form
      size="small"
      ref="form"
      :model="form"
      :label-width="formLabelWidth"
    >
      <el-form-item :label="$t('appsetting.version_android')" prop="versionAndroid">
        <el-input
          v-model="form.versionAndroid"
          :placeholder="$t('appsetting.input_android_version')"
        ></el-input>
      </el-form-item>
      <el-form-item :label="$t('appsetting.version_ios')" prop="versionIos">
        <el-input
          v-model="form.versionIos"
          :placeholder="$t('appsetting.input_ios_version')"
        ></el-input>
      </el-form-item>
      <el-form-item :label="$t('appsetting.hot_update_url')" prop="wgtUrl">
        <el-input v-model="form.wgtUrl"></el-input>
      </el-form-item>
      <el-form-item :label="$t('appsetting.full_update_android_url')" prop="pkgUrlAndroid">
        <el-input v-model="form.pkgUrlAndroid"></el-input>
      </el-form-item>
      <el-form-item :label="$t('appsetting.full_update_ios_url')" prop="pkgUrlIos">
        <el-input v-model="form.pkgUrlIos"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogVisible = false">{{$t('appsetting.cancel_button')}}</el-button>
        <el-button type="primary" @click="onSubmit" :loading="loading"
          >{{$t('appsetting.confirm_button')}}</el-button
        >
      </div>
    </template>
  </el-dialog>
</template>

<script>
import AppSettingApi from "@/api/appsetting.js";
export default {
  data() {
    return {
      /*左边长度*/
      formLabelWidth: "120px",
      /*是否显示*/
      loading: false,
      /*是否显示*/
      dialogVisible: false,
      /*form表单对象*/
      form: {
        versionAndroid: "",
        versionIos: "",
        wgtUrl: "",
        pkgUrlAndroid: "",
        pkgUrlIos: ""
      }
    };
  },
  props: ["open"],
  watch: {
    open: function (n, o) {
      if (n != o) {
        this.dialogVisible = this.open;
      }
    }
  },
  created() {},
  methods: {
    /*添加*/
    onSubmit() {
      let self = this;
      self.loading = true;
      AppSettingApi.addAppUpdate(self.form, true).then(data => {
        self.loading = false;
        ElMessage({
          message: $t("appsetting.add_success"),
          type: "success"
        });
        self.dialogFormVisible(true);
      }).catch(error => {
        self.loading = false;
      });
    },
    /*关闭弹窗*/
    dialogFormVisible(e) {
      if (e) {
        this.$emit("close", {
          type: "success",
          openDialog: false
        });
      } else {
        this.$emit("close", {
          type: "error",
          openDialog: false
        });
      }
    }
  }
};
</script>

